﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Lyon.Register
{
    static class EncryptUtil
    {
        static public string Encrypt(string value, string code)
        {
            //return Lyon.Utility.DESTool.Encrypt(value, code);
            using (MemoryStream stream = new MemoryStream())
            {
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter temp = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                temp.Serialize(stream, value);
                return Convert.ToBase64String(stream.ToArray());
            }
        }

        static public string Decrypt(string value, string code)
        {
            //return Lyon.Utility.DESTool.Decrypt(value, code);
            using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(value)))
            {
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter temp = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                return (string)temp.Deserialize(stream);
            }
        }
    }
}
